package com.wz.thread;

public class ThreadTest {
	private Data data;

	public ThreadTest(Data data) {
		this.data = data;
	}

	public void doWork(){
		new WorkerA(data).start();
		new WorkerB(data).start();
	}
	
	static class Data{
		private int data;

		public Data(int data) {
			this.data = data;
		}

		public int getData() {
			return data;
		}

		public void setData(int data) {
			this.data = data;
		}
		
	}
	
	class WorkerA extends Thread{
		private Data data;

		public WorkerA(Data data) {
			this.data = data;
		}

		@Override
		public void run() {
			for (int i = 0; i < 1000; i++) {
				System.out.println("A:" + this.data.getData());
				this.data.setData(this.data.getData() + 1);
			}
		}
		
	}

	class WorkerB extends Thread{
		private Data data;

		public WorkerB(Data data) {
			this.data = data;
		}
		@Override
		public void run() {
			for (int i = 0; i < 1000; i++) {
				System.out.println("B:" + this.data.getData());
				this.data.setData(this.data.getData() + 1);
			}
		}
	}
	public static void main(String[] args) {
		ThreadTest test = new ThreadTest(new Data(1));
		test.doWork();
	}
}